import { networkConfirmAcceptOrderApi, engineerConfirmAcceptOrderApi } from '@/api/order'
import { ref } from 'vue'

export const useNetworkConfirmAcceptOrder = () => {
  const acceptOrderLoading = ref(false)
  const acceptOrderParam = ref({
    id: '',
    networkId: '',
  })

  const acceptOrder = async () => {
    try {
      acceptOrderLoading.value = true
      const res = await networkConfirmAcceptOrderApi(acceptOrderParam.value)
      acceptOrderLoading.value = false
      return res.data
    } catch (error) {
      acceptOrderLoading.value = false
    }
  }

  return {
    networkAcceptOrderParam: acceptOrderParam,
    networkAcceptOrderLoading: acceptOrderLoading,
    networkAcceptOrder: acceptOrder,
  }
}

export const useEngineerConfirmAcceptOrder = () => {
  const acceptOrderLoading = ref(false)
  const acceptOrderParam = ref({
    id: '',
    networkId: '',
    engineerId: '',
  })

  const acceptOrder = async () => {
    try {
      acceptOrderLoading.value = true
      const res = await engineerConfirmAcceptOrderApi(acceptOrderParam.value)
      acceptOrderLoading.value = false
      return res.data
    } catch (error) {
      acceptOrderLoading.value = false
    }
  }

  return {
    engineerkAcceptOrderParam: acceptOrderParam,
    engineerAcceptOrderLoading: acceptOrderLoading,
    engineerAcceptOrder: acceptOrder,
  }
}
